<?php
/**
 * sfValidatorCUIT Valida el CUIT
 *
 * @author     Seewald Walter <walterseewald@gmail.com>
 * @version    SVN: $Id: sfValidatorCUIT.class.php 4347 2010-08-25 00:43:00 $
 * @filesource
 * @license GPL
 */
 
class sfValidatorCUIT extends sfValidatorBase {
 
    protected function configure($options = array(), $messages = array()) 
    {	
		$this->setMessage('invalid', '"%cuit%" no es un CUIT v&aacute;lido.');
		$this->addMessage('toshort', '"%cuit%" es un n&uacute;mero muy corto para ser un CUIT v&aacute;lido.');

    }
 
    protected function doClean($value)
    {
		$cuit = implode('',$value); //2038130437
		//$cuit = $value;
		if(strlen($cuit) == 11){
			$c = array(5,4,3,2,7,6,5,4,3,2);
			$s=0;
			foreach($c as $i => $v) $s+=$cuit[$i] * $v;
			
			if ($cuit[10] != (11-($s % 11)))
			{
			  throw new sfValidatorError($this, 'invalid', array('cuit' => implode('-',$value)));
			}
		}else{
			throw new sfValidatorError($this, 'toshort', array('cuit' => $cuit));
		}
		
		return implode('',$value);
    }
}
?>